package com.haven.webrobotserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.haven.webrobotserver.domain.ResultTestcaseTestdata;
import com.haven.webrobotserver.service.ResultTestcaseTestdataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/resultTestcaseTestdata")
@CrossOrigin("http://localhost:8080")
public class ResultTestcaseTestdataController {

    @Autowired
    private ResultTestcaseTestdataService resultTestcaseTestdataService;

    @PostMapping("/save")
    public JSONObject saveTestcaseResult(@RequestBody ResultTestcaseTestdata rtt){
        JSONObject result = new JSONObject();
        try{
            resultTestcaseTestdataService.saveOne(rtt);
            result.put("status",200);
        }catch (Exception e){
            e.printStackTrace();
            result.put("status",500);
        }

        return result;
    }

    @GetMapping("/getlistByBatch")
    public JSONObject getTestcaseTestdataResultList(@RequestParam(name = "batchId") int batchId){
        JSONObject result = new JSONObject();

        try{
            List<Map<String, String>> listByBatchId = resultTestcaseTestdataService.getListByBatchId(batchId);
            result.put("data",listByBatchId);
            result.put("status",200);
        }catch(Exception e){
            e.printStackTrace();
            result.put("status",500);
        }


        return result;
    }
}
